<?php

/**
 * Description of CmsManager_PDO
 *
 * @author FFOZEU
 */
namespace Applications\Modules\Cms\Models;

if( !defined('IN') ) die('Hacking Attempt');

class CmsManager_PDO extends CmsManager{
    //put your code here
    
        
    public function getCms(){
        $sql = 'SELECT c.*
                FROM '.$this->nameTable.' as c
                ORDER BY c.date_insere';
        $cms=$this->dao->query($sql);
        
        return $this->fecthAssoc_data($cms, $this->name);
                
    }
    
    public function addCms(array $param){
        $cms = new Cms($param);
        $sql='INSERT INTO '.$this->nameTable.'
              SET titre = :titre, texte = :texte, date_insere = :date_insere, date_maj = :date_maj';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':titre',$cms->getTitre());
        $req->bindParam(':texte',$cms->getTexte());
        $req->bindParam(':date_insere',$cms->getDate_insere());
        $req->bindParam(':date_maj',$cms->getDate_maj());
        
        return $req->execute();
    }
    
    public function updateCms(array $param){
        $cms = new Cms($param);
        $sql='UPDATE '.$this->nameTable.'
              SET titre = :titre, texte = :texte, date_maj = :date_maj
              WHERE id = :id';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':titre',$cms->getTitre());
        $req->bindParam(':texte',$cms->getTexte());
        $req->bindParam(':date_maj',$cms->getDate_maj());
        $req->bindParam(':id',intval($cms->getId()));
        
        return $req->execute();
    }
    
    public function getCmsById($id){
        
        return $this->fecthRow_data($this->findById($this->nameTable, $id), $this->name);
    }
    
    public function deleteCms(array $id){
        
        return $this->delete($this->nameTable, $id);
    }
}

?>
